BigDFT.Fragments module

Fragment Class

class Fragment(atomlist=None, xyzfile=None, posinp=None, astruct=None, system=None)[source]

Bases: collections.abc.MutableSequence

A fragment is a list of atoms in a system. Fragment might have quantities associated to it, like its electrostatic multipoles (charge, dipole, etc.) and also geometrical information (center of mass, principla axis etc.). A Fragment might also be rototranslated and combined with other moieteies to form a BigDFT.Systems.Systems.

Parameters
  • atomlist (list) – list of atomic dictionaries defining the fragment

  • xyzfile (BigDFT.IO.XYZReader) – an XYZ file to read from.

  • posinp (dict) – the posinp style dictionary from a logfile/input file.

  • astruct (dict) – a BigDFT atomic structure style dictionary.

  • system (BigDFT.Systems.System) – a BigDFT system, esssentially this reduces many fragments into a single fragment.

Todo

Define and describe if this API is also suitable for solid-state fragments

center_of_charge()[source]

The charge center which depends both on the position and net charge of each atom.

property centroid

The center of a fragment.

d0(center=None)[source]

Fragment dipole, calculated only from the atomic charges.

Parameters

center (list) – the center of charge of the fragment. If this is not present, the centroid is used.

d1(center=None)[source]

Fragment dipole including the atomic dipoles.

Parameters

center (list) – the center of charge of the fragment. If this is not present, the centroid is used.

ellipsoid(center=0.0)[source]

Todo: define the ellipsoid.

get_external_potential(units='bohr', charge_offset=False)[source]

Transform the fragment information into a dictionary ready to be put as an external potential.

Parameters

units (str) – the units of the external potential.

Returns

a dictionary describing the external potential for use in an input file.

Return type

(dict)

get_net_force()[source]

Returns the net force on a fragment in Ha/Bohr.

Returns

(list) Three values which describe the net force.

insert(index, value)[source]

S.insert(index, value) – insert value before index

property nel

The number of valence electrons of the atoms of the fragment

property q0

Provides the global monopole of the fragments given as a sum of the monopoles of the atoms.

qcharge()[source]

The net charge on a fragment.

rmsd(reference)[source]

Calculate the Reduced Mean Square displacement with a reference fragment.

rotate(x=None, y=None, z=None, units='radians')[source]

Rotate the fragment.

Parameters
  • x (float) – angle to rotate on the x axis.

  • y (float) – angle to rotate on the y axis.

  • z (float) – angle to rotate on the z axis.

  • units (str) – either radians or degrees.

rotate_on_axis(angle, axis, units='radians')[source]

Rotate a fragment along a specific axis.

Parameters
  • angle (float) – angle to rotate along the axis.

  • axis (list) – a list of floats defining the vector to rotate along.

  • units (str) – either radians or degrees.

serialize(name, units='bohr')[source]

Transform the fragment in a list that can be employed for the construction of dataframes or pandas series.

Parameters
  • name (str) – the name of the fragment

  • units (str) – the units for the positions

Returns

the serialized fragment

Return type

list

translate(vec)[source]

Translate the fragment along the vector provided.

Parameters

vec (list) – a list of x, y, z values describing the translation (AU).

This module contains data structures for describing fragments. Fragments are orders lists of atoms.

distance(i, j, cell=None)[source]

Distance between fragments, defined as distance between center of mass

Parameters
  • i (Fragment) – first fragment.

  • j (Fragment) – second fragment.

  • cell (array) – an array describing the unit cell.

Returns

the distance between centers of mass.

Return type

(float)

interpolate_fragments(A, B, steps, extrapolation_steps=0)[source]

Given two fragments A and B, this generates a list of Fragments that interpolate between A and B in a specified number of steps.

Parameters
Returns

a list of fragments interpolating between A and B including A and B.

Return type

(list)

lineup_fragment(frag)[source]

Align the principal axis of inertia of the fragments along the coordinate axis. Also shift the fragment such as its centroid is zero.

Parameters

(BigDFT.Fragments.Fragment) – the fragment to transform.

Returns

the transformed fragment.

Return type

(BigDFT.Fragments.Fragment)

pairwise_distance(i, j, cell=None)[source]

Distance between fragments, as defined by the distance between their two nearest atoms.

Parameters
  • i (Fragment) – first fragment.

  • j (Fragment) – second fragment.

  • cell (array) – an array describing the unit cell.

Returns

the pairwise distance between fragments.

Return type

(float)

Transformations

class RotoTranslation(frag1, frag2)[source]

Bases: object

Define a transformation which can be applied to a fragment. This rotation is defined by giving this class two fragments, and the rototranslation between those fragments is automatically computed.

Parameters
dot(frag)[source]

Apply the rototranslations on a fragment.

Parameters

frag (BigDFT.Fragments.Fragment) – the fragment to rototranslate.

Returns

the rototranslated fragment.

Return type

(BigDFT.Fragments.Fragment)

invert()[source]

Computes the inverse rototranslation.

class Rotation(R)[source]

Bases: BigDFT.Fragments.RotoTranslation

This class defines a simple rotation.

Parameters

t (list) – the vector describing the rotation.

class Translation(t)[source]

Bases: BigDFT.Fragments.RotoTranslation

This class defines a simple translation.

Parameters

t (list) – the vector describing the translation.

BigDFT.Fragments example

Below we show an example of using the fragment class.

def _example():
    """Example of using fragments"""
    from BigDFT.IO import XYZReader, XYZWriter
    from copy import deepcopy

    safe_print("Read in an xyz file and build from a list.")
    atom_list = []
    with XYZReader("SiO") as reader:
        for at in reader:
            atom_list.append(at)
    frag1 = Fragment(atomlist=atom_list)
    for at in frag1:
        safe_print(at.sym, at.get_position())
    safe_print("Centroid", frag1.centroid)
    safe_print()

    safe_print("Build from an xyz file directly.")
    reader = XYZReader("Si4")
    frag2 = Fragment(xyzfile=reader)
    for at in frag2:
        safe_print(at.sym, at.get_position())
    safe_print()

    safe_print("We can combine two fragments with +=")
    frag3 = deepcopy(frag1)
    frag3 += frag2
    for at in frag3:
        safe_print(at.sym, at.get_position())
    safe_print("Length of frag3", len(frag3))
    safe_print()

    safe_print("Since we can iterate easily, we can also write easily.")
    with XYZWriter("test.xyz", len(frag3), "angstroem") as writer:
        for at in frag3:
            writer.write(at)
    with open("test.xyz") as ifile:
        for line in ifile:
            safe_print(line)
    safe_print()

    safe_print("We can also extract using the indices")
    safe_print(dict(frag3[0]))
    sub_frag = frag3[1:3]
    for at in sub_frag:
        safe_print(dict(at))
    safe_print()